const mongoose = require('mongoose')
const mongodbUrl = 'mongodb://localhost:27017/chat' // 内网数据库
mongoose.connect(mongodbUrl,
    {
      useNewUrlParser: true ,
      useUnifiedTopology: true,
    }, 
   function (err) {
    if (err) {
      console.log(err)
    } else {
      console.log('数据库连接成功,可以搞事情!')
    }
  })
  const Schema = mongoose.Schema

  const userSchema = new Schema({
      userid: String,
      online: Boolean,
      username: String,
      avatar: String,
      passwd: String,
  })

  const friendsSchema = new Schema({
      userid: String,
      friend: {
        type: mongoose.Schema.ObjectId,
        ref: 'User'
      }
  })

  exports.User = mongoose.model('User', userSchema);
  exports.Friends = mongoose.model('Friends', friendsSchema);